package com.prb.ip.filter;


import com.prb.ip.filter.common.IpHolder;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

import java.util.Map;

@Activate(group = {CommonConstants.CONSUMER })
public class RpcIpTakeFilter implements Filter {

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        // 保存IP地址信息1
        Map<String, String> attachments = RpcContext.getContext().getAttachments();
        attachments.put("requestId" , IpHolder.self.getIp());
        return invoker.invoke(invocation);
    }

}
